package com.xykj.enterprise.wechat.ext.api.externalcontact;

import com.xykj.enterprise.wechat.bean.ext.externalcontact.moment.GetMomentCommentsVo;
import com.xykj.enterprise.wechat.ext.service.customer.ExternalContactService;
import com.ydn.appserver.Action;
import com.ydn.appserver.Request;
import com.ydn.appserver.Response;
import com.ydn.appserver.annotations.Function;
import com.ydn.appserver.annotations.Parameter;
import com.ydn.appserver.annotations.Type;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;

@Slf4j
@Function(description = "获取客户朋友圈的互动数据", parameters = {
        @Parameter(name = "access_token", type = Type.String, description = "access_token", required = true),

        @Parameter(name = "moment_id", type = Type.String, description = "朋友圈id,仅支持企业发表的朋友圈id", required = true),
        @Parameter(name = "userid", type = Type.String, description = "企业发表成员userid，如果是企业创建的朋友圈，可以通过获取朋友圈成员任务列表获取已发表成员userid，如果是个人创建的朋友圈，创建人userid就是发表成员userid", required = true),
})
@Component
public class GetMomentComments implements Action {

    @Autowired
    private ExternalContactService externalContactService;

    @Override
    public Response execute(Request request) throws Exception {
        String moment_id = request.getString("moment_id");
        String userid = request.getString("userid");

        HashMap<String, Object> params = new HashMap<String, Object>();
        params.put("userid", userid);
        params.put("moment_id", moment_id);


        GetMomentCommentsVo rsp = externalContactService.getMomentComments(
                request.getString("access_token"), params
        );
        if (rsp.getErrcode() != 0) {
            return Response.fail(rsp.getErrmsg());
        }
        return Response.success().put("data", rsp);
    }
}
